#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

[ -n "$CI" ] && exit 0

# 增加超时时间，防止大型项目检查超时
export LINT_STAGED_TIMEOUT=120000

PATH="/usr/local/bin:$PATH"

# 设置更大的Node内存限制
export NODE_OPTIONS="--max-old-space-size=8192"

# 检查是否有文档相关变更，如果只有文档变更，跳过lint
# DOCS_ONLY=$(git diff --cached --name-only | grep -v "^docs/" | wc -l)
# if [ "$DOCS_ONLY" -eq 0 ]; then
#   echo "✅ 只有文档变更，跳过lint检查"
#   exit 0
# fi

# Format and submit code according to lintstagedrc.js configuration
echo "🔍 运行lint-staged检查..."
pnpm exec lint-staged || {
  echo "❌ lint-staged失败。"
  echo "👉 你可以使用 git commit --no-verify 跳过检查，但请确保代码质量。"
  exit 1
}

echo "✅ 预提交检查通过!"
